<?php
namespace app\api\controller\service;

use app\common\controller\Api;


/**
 * 首页接口
 */
class Follow extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];

    /**
     * 更新关注状态
     * @return void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function handleFollow()
    {
        $uid = $this->auth->id;
        $type = input('type/d','');
        $state = input('state/d',0);
        $follow_id = input('follow_id/d','');
        $info = model('app\api\model\service\Follow')->where(['user_id'=>$uid,'follow_id'=>$follow_id,'type'=>$type])->field('id,state')->find();
        ($info && $info['state'] == $state) && $this->error('关注状态异常');
        $re = \app\api\model\service\Follow::updateFollow(['user_id'=>$uid,'type'=>$type,'follow_id'=>$follow_id,'state'=>$state],$info);
        if(!$re)
        {
            $this->error('状态更新异常');

        }
        $this->success('关注状态已更新');
    }


    public function getList()
    {
        $get = input('get.','','trim,strip_tags');
        $get['user_id'] = $this->auth->id;
        $list = \app\api\model\service\Follow::getList($get);
        $this->success('信息返回成功',$list);
    }
}
